#mapping-script
# -*- coding: ms949 -*-
import bots.transform as transform
import bots.usersys.mappings.utils as utils

def main(inn,out):
    #XML
    rootelement = '{urn:kr:gov:kcs:data:standard:KCS_DeclarationOfReleaseSchemaModule:1:0:0}DeclarationOfRelease'
    ns1 = '{urn:kr:gov:kcs:data:standard:KCS_DeclarationOfReleaseSchemaModule:1:0:0}'
    ns2 = '{urn:kr:gov:kcs:common:standard:KCS_ReusableAggregateBusinessInformationEntitySchemaModule:1:0:0}'
    
        
    #Read from inn by EDIFACT order
    DocumentTypeCode = inn.get({'BOTSID':'UNH'},{'BOTSID':'BGM','C002.1001':None})
    DocumentReferenceID = inn.get({'BOTSID':'UNH'},{'BOTSID':'BGM','1004':None})
    DocumentFunctionTypeCode = inn.get({'BOTSID':'UNH'},{'BOTSID':'BGM','1225':None})
    
    ReleaseDateTime = inn.get({'BOTSID':'UNH'},{'BOTSID':'DTM','C507.2005':'261','C507.2380':None})
    
    CargoReleaseTypeCode = inn.get({'BOTSID':'UNH'},{'BOTSID':'GIS','C529.1131':'148','C529.7365':None})
    PartitionReleaseTypeCode = inn.get({'BOTSID':'UNH'},{'BOTSID':'GIS','C529.1131':'121','C529.7365':None})
    ReleasePeriodExtensionTypeCode = inn.get({'BOTSID':'UNH'},{'BOTSID':'GIS','C529.1131':'5DM','C529.7365':None})
    
    UCRIdentificationID = inn.get({'BOTSID':'UNH'},{'BOTSID':'RFF','C506.1153':'XC','C506.1154':None})
    UCRMasterBLSequenceID = inn.get({'BOTSID':'UNH'},{'BOTSID':'RFF','C506.1153':'XC','C506.1156':None})
    UCRHouseBLSequenceID = inn.get({'BOTSID':'UNH'},{'BOTSID':'RFF','C506.1153':'XC','C506.4000':None})
    PreviousCustomsDocumentReferenceID = inn.get({'BOTSID':'UNH'},{'BOTSID':'RFF','C506.1153':'ABP','C506.1154':None})
    PeriodExtensionPreviousCustomsDocumentReferenceID = inn.get({'BOTSID':'UNH'},{'BOTSID':'RFF','C506.1153':'ABL','C506.1154':None})
    
    ReleaseGoodsPackagingQuantity = inn.get({'BOTSID':'UNH'},{'BOTSID':'GID','C213#1.7224':None})
    
    ReleaseMeasure = inn.get({'BOTSID':'UNH'},{'BOTSID':'GID'},{'BOTSID':'MEA','C174.6314':None})
    ReleaseMeasure_measureUnitCode = 'KG'
    
    ReleaseCarriedInGradeNumeric = inn.get({'BOTSID':'UNH'},{'BOTSID':'CNT','C270.6069':'6','C270.6066':None})

    #Write to out by XML order
    out.put({'BOTSID':rootelement,ns1+'ReleaseDateTime':utils.isoDateTimeFormat(ReleaseDateTime)})
    out.put({'BOTSID':rootelement,ns1+'CargoReleaseTypeCode':CargoReleaseTypeCode})
    out.put({'BOTSID':rootelement,ns1+'PartitionReleaseTypeCode':PartitionReleaseTypeCode})
    out.put({'BOTSID':rootelement,ns1+'ReleasePeriodExtensionTypeCode':ReleasePeriodExtensionTypeCode})
    out.put({'BOTSID':rootelement,ns1+'ReleaseMeasure':ReleaseMeasure})
    out.put({'BOTSID':rootelement,ns1+'ReleaseMeasure__measureUnitCode':ReleaseMeasure_measureUnitCode})
    out.put({'BOTSID':rootelement,ns1+'ReleaseCarriedInGradeNumeric':ReleaseCarriedInGradeNumeric})
    
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'Document',ns2+'TypeCode':DocumentTypeCode})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'Document',ns2+'referenceID':DocumentReferenceID})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'Document',ns2+'FunctionTypeCode':DocumentFunctionTypeCode})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'UCR',ns2+'IdentificationID':UCRIdentificationID})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'UCR',ns2+'MasterBLSequenceID':UCRMasterBLSequenceID})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'UCR',ns2+'HouseBLSequenceID':UCRHouseBLSequenceID})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'PreviousCustomsDocument',ns2+'referenceID':PreviousCustomsDocumentReferenceID})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'PeriodExtensionPreviousCustomsDocument',ns2+'referenceID':PeriodExtensionPreviousCustomsDocumentReferenceID})
    out.put({'BOTSID':rootelement},{'BOTSID':ns1+'ReleaseGoodsPackaging',ns2+'Quantity':ReleaseGoodsPackagingQuantity})
